package site.luojie.core.factory;

import site.luojie.core.bean.Bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author jie.luo
 * @Create: 2020-05-06 00:37
 **/
public abstract class AbstractApplicationContext implements BeanFactory {

    protected List<Bean> beans = new ArrayList<>();

    protected Map<String, Object> beanMap = new HashMap<>();

    /**
     * 具体子类的获取Bean的实现方法
     *
     * @param name bean名称
     * @return bean
     */
    public abstract Object getContextBean(String name);

    /**
     * 具体子类的获取Bean的实现方法
     *
     * @param requiredType Class
     * @param <T>          泛型
     * @return bean
     */
    public abstract <T> T getContextBean(Class<T> requiredType);

    @Override
    public Object getBean(String name) {
        return getContextBean(name);
    }

    @Override
    public <T> T getBean(Class<T> requiredType) {
        return getContextBean(requiredType);
    }
}
